<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>layui</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet"
	th:href="@{/manager/layui/lib/layui-v2.5.5/css/layui.css}"
	href="/manager/layui/lib/layui-v2.5.5/css/layui.css" media="all">
<link rel="stylesheet" th:href="@{/manager/layui/css/public.css}"
	href="/manager/layui/css/public.css" media="all">
<style>
body {
	background-color: #ffffff;
}
</style>
</head>
<body>

	<div id="tree1" class="demo-tree demo-tree-box"></div>
	<br>
	<div class="layui-btn-group">
		<button type="button" class="layui-btn layui-btn-normal" id="submit">确定</button>
	</div>
	<input type="hidden" id="clist"   th:value="${list != null} ? ${list}"/>
	<input type="hidden" id="roleId" name="roleId" th:value="${roleId!=null}? ${roleId}">
	<script th:src="@{/manager/layui/lib/layui-v2.5.5/layui.js}"
		src="/manager/layui/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
	<script>
		layui.use([ 'tree', 'util' ], function() {
			var tree = layui.tree, util = layui.util, $ = layui.$;
			var a = $("#clist").val();
			var index = parent.layer.getFrameIndex(window.name);
			$.ajax({
				url : "/menu/treelist",
				type : "post",
				success : function(data) {
					var redsult = JSON.stringify(data.data);
					tree.render({
						id : "treeid",
						showCheckbox : true,
						elem : '#tree1', //默认是点击节点可进行收缩
						data : data.data
					});
					tree.setChecked('treeid',JSON.parse(a));
				},
				fail : function() {
					layer.msg("获取失败，请稍后重试");
				}
			});

			
			$("#submit").click(function() {
				var checkedData = tree.getChecked('treeid'); //获取选中节点的数据
				console.info("---"+$("#roleId").val());
				$.ajax({
					url:"/role/modifyRolePremission?roleId="+$("#roleId").val(),
// 					url:"/role/modifyRolePremission",
					data:JSON.stringify(checkedData),
					type:"post",
					contentType:"application/json",
					dataType:"json",
					success: function(){
						layer.alert("操作成功",function(){
// 							$("#clist").val("");
							parent.layer.close(index);
						});
						
					}
				});
			});

		});
	</script>
</body>
</html>